//Page Object
Page({
  data: {
    url: '',
    title: '',
    modalName:'',
    show:false,
    storageData:[],
    stepList: [{
      step: '一',
      color:'red',
      url: '../../Images/teachExample/1.png'
    }, {
      step: '二',
        color: 'yellow',
        url: '../../Images/teachExample/2.png'
    }, {
      step: '三',
        color: 'blue',
        url: '../../Images/teachExample/3.png'
    }, {
      step: '四',
        color: 'green',
        url: '../../Images/teachExample/4.png'
    }, {
      step: '五',
        color: 'cyan',
        url: '../../Images/teachExample/5.png'}
    ]
  },
  // 测试网址：http://www.iqiyi.com/v_19rr7q1fy0.html
  //options(Object)
  //获取input的url地址
  getInputValue: function(e) {
    this.data.url = e.detail.value
  },
  //点击获取解析url地址
  getRequestUrl: function() {
    if(this.data.url!=''){
    let that = this
    var firsturl = 'https://jx.618g.com/?url='
    var currenturl = this.data.url
    wx: wx.request({
      url: firsturl + currenturl,
      success: function(res) {
        var html = res.data
        console.log(html)
        var url_exgexp = RegExp('[a-zA-z]+://[^\s]*.m3u8')
        var title_exgexp = RegExp('[^\x00-\xff]+')
        var url = html.match(url_exgexp)
        var title = html.match(title_exgexp)
        if(url_exgexp.test(html)){
          that.setData({
            url: url[0],
            title: title
          })
          wx:wx.setStorage({
            key: 'titlekey',
            data: {title:title,url:url[0]},
          })
        }
        else{
          wx: wx.showToast({
            title: '你输入的地址无效，请重新更换',
            icon: 'none',
            image: '',
            duration: 2000,
          })
        }
        console.log(html)
        console.log(url)
        console.log(title)
      }
    })}
    else{
      wx:wx.showToast({
        title: '请输入URL地址',
        icon: 'none',
        image: '',
        duration: 1000,
      })
    }
  },
  WhatchVideo: function() {
    if (this.data.title != "") {
      wx: wx.redirectTo({
        url: '../OpenVideo/OpenVideo?url=' + this.data.url + '&title=' + this.data.title,
        success:function(){
          wx:wx.getStorage({
            key: 'titlekey',
            success: function(res) {
              this.data.storageData.push(res.data)
            }
          })
        }
      })
    }
    else {
      wx:wx.showToast({
        title: '抱歉，没有找到电影',
        icon: 'loading',
        image: '',
        duration: 1000,
      })
    }
  },
  onLoad: function(options) {

  },
  noneBlur:function(){
    this.setData({
      modalName: ''
    })
  },
  showThough:function(){
    var that=this
    this.setData({
      modalName:'Modal',
      show:true
    })
    wx: wx.getStorage({
      key: 'titlekey',
      success: function (res) {
        // this.data.storageData=res.data.title
        that.setData({
          storageData:res.data
        })
      }
    })
  },
  onReady:function(){

  },
});